package com.xuxueli.applyModules.commont;

import org.springframework.util.ConcurrentReferenceHashMap;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 测试缓存是否有值，重启会消失
 */
public class TestConcurrenHashMapWeek {

    private static Map<String, Object> infoMap = new ConcurrentReferenceHashMap<>(16,
            ConcurrentReferenceHashMap.ReferenceType.WEAK);

    public static void set(String key, Object object) {
        infoMap.put(key, object);
    }

    public static void remove(String key) {
        infoMap.remove(key);
    }

    public static Object get(String key) {
        return infoMap.get(key);
    }

    private static Map<Long, String> conMap = new ConcurrentHashMap<Long, String>();

    public static String getValue(Long id){
        return conMap.get(id);
    }

    public static void setValue(Long id,String value){
        conMap.putIfAbsent(id,value);
    }

    public static void removeValue(Long id){
        conMap.remove(id);
    }



}